using Godot;
using System;
[GlobalClass]
public partial class Tasks : Node
{
	public enum State
	{
		DISABLE,
		WAITING,
		COMPLETED
	}
	public enum Type
	{
		COLLECT,
		REACH,
		TALK,
		PARENT
	}
	[Export]
	public string taskID = "";//任务代号，如：主线_1
	[Export]
	public string name = "任务名称";
	[Export]
	public State CurrentState = State.DISABLE;
	[Export]
	public Type CurrentType;
	[Export]
	public string ParentTask = "";
	[Export]
	public bool follow;
	[Export]
	public string target;
	[Export]
	public string nexttask;
	[Export]
	public string description;


	public void ParentTaskComplete(Tasks childtask)
	{
		if(childtask.ParentTask == "")
		{return;}
		var Game = GetNode<Game>("/root/Game");
		TaskManager _taskManager = Game.get_player().GetNode<TaskManager>("%TaskManager") as TaskManager;
		foreach(Tasks parent in _taskManager.parentTasks)
		{
			if(parent.name == childtask.ParentTask)
			{
				parent.CurrentState = State.COMPLETED;
				break;
			}
		}
	}

	public void ChildTaskComplete(Tasks task)
	{
		task.CurrentState = State.COMPLETED;
		if(task.nexttask == null||task.nexttask == "")
		{
			ParentTaskComplete(task);
			return;}
		var Game = GetNode<Game>("/root/Game");
		TaskManager _taskManager = Game.get_player().GetNode<TaskManager>("%TaskManager");
		_taskManager.AcceptTask(task.nexttask);
		_taskManager.runningTasks.Remove(this);
		_taskManager.completedTasks.Add(this);
	}
}
